/**
 * 功能描述 列表
 */
define(function (require, exports, module) {
	var Grid = require("grid"); 	
	var aw = require("ajaxwrapper")
	var Dialog = require("dialog");
	var store =require("store");
	var activeUser = store.get("user");	
	
	var visitWay = require("../store/visitway");
	
    var instance = {
        initComponent: function (params, widget) {
        	var grid = new Grid({
                parentNode : ".J-grid",
                url : "api/visitway/query",
                params : function(){
                		var obj={
    	     					fetchProperties:visitWay.fetchProperties
                		}
                		return obj;
                },
                model : {
                    columns : [{
                        name : "name",
                        label : "访问方式"
                    },{
                        name : "description",
                        label : "描述",
                    },{
                        name : "show",
                        label : "操作",
    					format:"button",
						formatparams:[{
							id:"edit",
							icon:"icon-edit",
							handler:function(index,data,rowEle){
								/*aw.ajax({
									url:"api/perorder/query",
									data:{
										"servicePackage.pkServicePackage":data.pkServicePackage
									},
									dataType:"json",
									success:function(datas){
										if(datas.length != 0){
											Dialog.alert({content:"该条已经被引用，无法编辑。"});
											return false;
										}else{
											widget.get("form").reset();
											widget.hide([".J-grid"]).show([".J-form"]);
											widget.get("subnav").hide(["add"]).show(["return"]);
											widget.get("form").setData(data);
										}
									}
								});*/
								widget.get("form").reset();
								widget.hide([".J-grid"]).show([".J-form"]);
								widget.get("subnav").hide(["add"]).show(["return"]);
								widget.get("form").setData(data);
								widget.get("form").setValue("organization",data.organization.pkOrganization);
							}
						},{
							id:"delete",
							icon:"icon-remove",
							handler:function(index,data,rowEle){
								aw.del("api/visitway/"+data.pkVisitWay+"/delete",function() {
									grid.refresh();
								});	
								/*aw.ajax({
									url:"api/perorder/query",
									data:{
										"servicePackage.pkServicePackage":data.pkServicePackage
									},
									dataType:"json",
									success:function(datas){
										if(datas.length != 0){
											Dialog.alert({content:"该条已经被引用，无法删除。"});
											return false;
										}else{
											aw.del("api/allergicfile/" + data.pkServicePackage + "/deletespservicepackage",function() {
	  											widget.get("grid").refresh();
	  										});
										}
									}
								});*/
							}
						}]
                    }]
                }
            });
        	widget.set("grid",grid);
        }
    };
    module.exports = instance;
});
